package com.woniuxy.stage3demo.controller.otherPzc;

import com.github.pagehelper.PageInfo;
import com.woniuxy.stage3demo.bean.ResultMsg;
import com.woniuxy.stage3demo.bean.otherPzc.AdsBean;
import com.woniuxy.stage3demo.bean.otherPzc.ApplyForDataConfigBean;
import com.woniuxy.stage3demo.pageHelper.PageRequest;
import com.woniuxy.stage3demo.pageHelper.TableResult;
import com.woniuxy.stage3demo.service.otherPzc.IApplyForDataConfigService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RequestMapping("/applydata")
@RestController
public class ApplyForDataConfigController {

    @Resource
    private IApplyForDataConfigService applyForDataConfigServiceImpl;

    @RequestMapping(value = "/page",produces = {"application/json;charset=utf-8"})
    public TableResult<ApplyForDataConfigBean> findAllByParams(PageRequest request, ApplyForDataConfigBean applyForDataConfigBean){
        PageInfo<ApplyForDataConfigBean> pageInfo = applyForDataConfigServiceImpl.findAllByParams(request, applyForDataConfigBean);
        return new TableResult<>(pageInfo.getTotal(),pageInfo.getList());
    }
    @PutMapping(value = "/infor",produces = {"application/json;charset=utf-8"})
    public ResultMsg update(@RequestBody ApplyForDataConfigBean applyForDataConfigBean){
        ResultMsg res = new ResultMsg(200,"操作成功",null);
        if(applyForDataConfigServiceImpl.updateApplyForDataConfig(applyForDataConfigBean) == 1){
            return res;
        }else{
            res.setCode(10000);
            res.setMsg("修改失败");
            return res;
        }
    }
    @PostMapping(value = "/more/{name}",produces = {"application/json;charset=utf-8"})
    public ResultMsg update(@PathVariable String name){
        ResultMsg res = new ResultMsg(200,"操作成功",null);
        ApplyForDataConfigBean applyForDataConfigBean = new ApplyForDataConfigBean();
        applyForDataConfigBean.setConfigName(name);
        applyForDataConfigBean.setNecessary(0);
        applyForDataConfigBean.setAttachment(0);
        applyForDataConfigBean.setReadyBefore(0);
        if(applyForDataConfigServiceImpl.saveApplyForDataConfig(applyForDataConfigBean) == 1){
            return res;
        }else{
            res.setCode(10000);
            res.setMsg("修改失败");
            return res;
        }
    }

}
